package html5environment;


import java.util.Arrays;














import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.ToolTip;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;





public class PageOne  extends WizardPage {
	 private Text applicationId;
	 private Text groupId;
	 private Text titles;
	 private Combo scapi;
	 private Spinner build;
	 private Text version;
	 private Composite container;
	 private Text url;
	 private String selected;
	 

	  public PageOne() {
	    super("Dymora App");
	    setTitle("Dymora App");
	    setDescription("This information will be included on MANIFEST.xml");
	  }

	  @Override
	  public void createControl(final Composite parent) {
	    container = new Composite(parent, SWT.NONE);
	    GridLayout layout = new GridLayout();
	    container.setLayout(layout);
	    layout.numColumns = 2;
//	    ToolBar toolBar1 = new ToolBar(container, SWT.FLAT | SWT.RIGHT);
//	  	ToolItem tltmNewItem1 = new ToolItem(toolBar1, SWT.NONE);
//	  	tltmNewItem1.setImage(SWTResourceManager.getImage(PageOne.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
//	  	tltmNewItem1.setToolTipText("Please enter an Id for Application (e.g. mail, storage)");
//	  	tltmNewItem1.setText("Application Id");
	    CLabel lblNewLabel_7 = new CLabel(container, SWT.NONE);
	  	lblNewLabel_7.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
	  	lblNewLabel_7.setToolTipText("Please enter an Id for Application (e.g. mail, storage)");
	  	lblNewLabel_7.setText("Application Id");
	    applicationId = new Text(container, SWT.BORDER | SWT.SINGLE);
	    applicationId.setText("");
	    CLabel lblNewLabel_6 = new CLabel(container, SWT.NONE);
		lblNewLabel_6.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_6.setToolTipText("Please enter a Group Id for the application (e.g. sc.app.builtin)");
		lblNewLabel_6.setText("Group Id");
	    groupId = new Text(container, SWT.BORDER | SWT.SINGLE);
	    groupId.setText("sc.app.builtin");
	    CLabel lblNewLabel_5 = new CLabel(container, SWT.NONE);
		lblNewLabel_5.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_5.setToolTipText("Please enter a display name for the application (e.g. Secure Browser). \n If this information is missing, the display name will be the same of application-id");
		lblNewLabel_5.setText("Title (optional)");
	    titles = new Text(container, SWT.BORDER | SWT.SINGLE);
	    titles.setText("");
	    CLabel lblNewLabel_4 = new CLabel(container, SWT.NONE);
		lblNewLabel_4.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_4.setToolTipText("Please enter a version for the application (e.g. 1.0.1");
		lblNewLabel_4.setText("Version (optional)");
	    version = new Text(container, SWT.BORDER | SWT.SINGLE);
	    version.setText("");
	  	CLabel lblNewLabel_3 = new CLabel(container, SWT.NONE);
		lblNewLabel_3.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_3.setToolTipText("Please enter a build number version for the application");
		lblNewLabel_3.setText("Build Number");
	  	build = new Spinner(container, SWT.BORDER);	 
	  	build.setValues(1, 1, 100, 0, 1, 10);
	  	CLabel lblNewLabel_2 = new CLabel(container, SWT.NONE);
		lblNewLabel_2.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_2.setToolTipText("Please select the required version of Secure Container API for this application");
		lblNewLabel_2.setText("SC API Version");
	    scapi = new Combo(container, SWT.READ_ONLY);
	    scapi.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
	    String[] version = new String[]{"default", "1.0", "2.0", "3.0"};
	    
	    
	    Arrays.sort(version);
	   
	    for(int i=0; i<version.length; i++)
	        scapi.add(version[i]); 
	    
	    scapi.select(3);	       
	    applicationId.addKeyListener(new KeyListener() {

	      @Override
	      public void keyPressed(KeyEvent e) {
	      }

	      @Override
	      public void keyReleased(KeyEvent e) {
	        if (!applicationId.getText().isEmpty())  {
	        	setPageComplete(true);}
	        else{
	        	setPageComplete(false);
	          }

	        
	      }

	    });
	    
	    CLabel lblNewLabel_1 = new CLabel(container, SWT.NONE);
		lblNewLabel_1.setImage(SWTResourceManager.getImage(PageTwo.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
		lblNewLabel_1.setToolTipText("Please choose a version of cordova.js (version 2.6 is required).");
		lblNewLabel_1.setText("Cordova");
		url =  new Text(container, SWT.BORDER | SWT.READ_ONLY);
		url.setSize(50, 10);
		url.setEnabled(false);
		url.setEditable(false);
	  	Button browse = new Button(container, SWT.PUSH | SWT.RIGHT);
		browse.setText("Browse...");
		browse.addSelectionListener(new SelectionAdapter() {
		      @Override
		      public void widgetSelected(SelectionEvent e) {
		    	  Shell shell = parent.getShell();
		          openDialogs(shell);
		        
		      }
		    });
	    
	    
	    

	    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
	    applicationId.setLayoutData(gd);
	    groupId.setLayoutData(gd);
	    titles.setLayoutData(gd);

	    setControl(container);
	    setPageComplete(false);

	  }

	public Combo getScapi() {
		return scapi;
	}

	public Text getApplicationId() {
		return applicationId;
	}

	public Text getGroupId() {
		return groupId;
	}

//
	public Text getVersion() {
		return version;
	}

	public Spinner getBuild() {
		return build;
	}

	public Text getTitles() {
		return titles;
	}
	
	 public Text getUrl() {
		return url;
	}

	private void openDialogs(Shell shell) {
		    // File standard dialog
		    FileDialog fileDialog = new FileDialog(shell);
		    // Set the text
		    fileDialog.setText("Select File");
		    // Set filter on .txt files
		    fileDialog.setFilterExtensions(new String[] { "*.js" });
		    // Open Dialog and save result of selection
		    selected = fileDialog.open();
		    url.setText(selected);
		    
		    

	  
}

}